﻿using Apps.Common;
using Apps.Models;
using System.Linq;
using System.Collections.Generic;
using System;
using Apps.Models.LMS;

namespace Apps.BLL.LMS
{
    public partial class LMS_TEMPLATE_DETAILBLL
    {

        public override List<LMS_TEMPLATE_DETAILModel> GetListByParentId(ref GridPager pager, string queryStr, object parentId)
        {
            IQueryable<LMS_TEMPLATE_DETAIL> queryData = null;
            string pid = parentId.ToString();
            if (pid != "0")
            {
                queryData = m_Rep.GetList(a => a.TEMPLATE_ID == pid);
            }
            else
            {
                queryData = m_Rep.GetList();
            }
            if (!string.IsNullOrWhiteSpace(queryStr))
            {
                queryData = m_Rep.GetList(
                            a => (
                                    a.TEMPLATE_ID.Contains(queryStr)
                                   || a.INDEX_ID.Contains(queryStr)
                                 )
                            );
            }
            pager.totalRows = queryData.Count();
            queryData = LinqHelper.SortingAndPaging(queryData, pager.sort, pager.order, pager.page, pager.rows);
            return CreateModelList(ref queryData);
        }
        public override List<LMS_TEMPLATE_DETAILModel> CreateModelList(ref IQueryable<LMS_TEMPLATE_DETAIL> queryData)
        {

            List<LMS_TEMPLATE_DETAILModel> modelList = (from r in queryData
                                                        select new LMS_TEMPLATE_DETAILModel
                                                        {
                                                            VALUE_SHOW = r.VALUE_SHOW,
                                                            VALUE_TYPE = r.VALUE_TYPE,
                                                            VALUE_MAX = r.VALUE_MAX,
                                                            VALUE_MIN = r.VALUE_MIN,
                                                            INDEX_ID = r.INDEX_ID,
                                                            TEMPLATE_ID = r.TEMPLATE_ID
                                                        }).ToList();
            return modelList;
        }
        public override LMS_TEMPLATE_DETAILModel GetById(object id)
        {
            if (IsExists(id))
            {

                LMS_TEMPLATE_DETAIL entity = m_Rep.GetById(id);
                LMS_TEMPLATE_DETAILModel model = new LMS_TEMPLATE_DETAILModel();
                model.VALUE_SHOW = entity.VALUE_SHOW;
                model.VALUE_TYPE = entity.VALUE_TYPE;
                model.VALUE_MAX = entity.VALUE_MAX;
                model.VALUE_MIN = entity.VALUE_MIN;
                model.INDEX_ID = entity.INDEX_ID;
                model.TEMPLATE_ID = entity.TEMPLATE_ID;
                return model;
            }
            else
            {
                return null;
            }
        }
    }
}

